﻿'   This is generated Code:
'   Class Created by Script @ createclass.aspx
'   collectionclasstemplate2.5.txt
'
'   part of WHMCSdotnet (http://whmcsdotnet.wordpress.com)
'
'   Copyright (C) 2009-2011 Mark Castle <markcastle@gmail.com>
'   All rights reserved. 
'   Copyright (C) 2009-2011 Secura Hosting Ltd <code@securahosting.com>.
'   All rights reserved.
' 
'   Redistribution and use in source and binary forms, with or without modification,
'   are permitted provided that the following conditions are met:
' 
'   - Redistributions of source code must  retain  the  above copyright notice, this
'     list of conditions and the following disclaimer.
' 
'   - Redistributions in binary form  must  reproduce the  above  copyright  notice,
'     this list of conditions  and  the  following  disclaimer in  the documentation
'     and/or other materials provided with the distribution.
' 
'   - Neither  the  name  of  Secura Hosting Ltd, Mark Castle  nor the names of  its
'     contributors may be used to endorse or  promote  products  derived  from  this
'     software without specific prior written permission.
' 
'   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
'   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,  BUT  NOT  LIMITED TO, THE IMPLIED
'   WARRANTIES  OF  MERCHANTABILITY   AND  FITNESS  FOR  A  PARTICULAR  PURPOSE  ARE
'   DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
'   ANY DIRECT, INDIRECT, INCIDENTAL,  SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL DAMAGES
'   (INCLUDING, BUT NOT LIMITED TO,  PROCUREMENT  OF  SUBSTITUTE  GOODS OR SERVICES;
'   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)  HOWEVER  CAUSED AND ON
'   ANY  THEORY  OF  LIABILITY,  WHETHER  IN  CONTRACT,  STRICT  LIABILITY,  OR TORT
'   (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING  IN  ANY WAY OUT OF THE USE OF THIS
'   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


Option Explicit On
Option Strict On

Imports System
Imports System.Reflection
Imports System.Collections
Imports System.Diagnostics


Namespace Secura.WHMCS

    Public Class AddClient
        Inherits Secura.WHMCS.APIBaseType

        Private Const MODULE_NAME As String = "Secura.WHMCS.AddClient"

#Region "Properties"

        Private _FirstName As String = ""
        Private _LastName As String = ""
        Private _CompanyName As String = ""
        Private _Email As String = ""
        Private _Address1 As String = ""
        Private _Address2 As String = ""
        Private _City As String = ""
        Private _State As String = ""
        Private _Postcode As String = ""
        Private _Country As String = ""
        Private _PhoneNumber As String = ""
        Private _Password2 As String = ""
        Private _Currency As Integer = 0
        Private _GroupId As Integer = 0
        Private _Notes As String = ""
        Private _CCType As String = ""
        Private _CardNum As String = ""
        Private _ExpDate As String = ""
        Private _StartDate As String = ""
        Private _IssueNumber As String = ""
        Private _CustomFields As String = ""
        Private _NoEmail As Boolean = False
        Private _SkipValidation As Boolean = False


        ' -----------------------------------------------
        ' -- Properties
        ' -----------------------------------------------

        ''' <summary>
        ''' FirstName Property (r/w)
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property FirstName() As String
            Get
                Return _FirstName
            End Get

            Set(ByVal Value As String)
                _FirstName = Value
            End Set
        End Property

        ''' <summary>
        ''' LastName Property (r/w)
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property LastName() As String
            Get
                Return _LastName
            End Get

            Set(ByVal Value As String)
                _LastName = Value
            End Set
        End Property

        ''' <summary>
        ''' CompanyName Property (r/w)
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property CompanyName() As String
            Get
                Return _CompanyName
            End Get

            Set(ByVal Value As String)
                _CompanyName = Value
            End Set
        End Property

        ''' <summary>
        ''' Email Property (r/w)
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Email() As String
            Get
                Return _Email
            End Get

            Set(ByVal Value As String)
                _Email = Value
            End Set
        End Property

        ''' <summary>
        ''' Address1 Property (r/w)
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Address1() As String
            Get
                Return _Address1
            End Get

            Set(ByVal Value As String)
                _Address1 = Value
            End Set
        End Property

        ''' <summary>
        ''' Address2 Property (r/w)
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Address2() As String
            Get
                Return _Address2
            End Get

            Set(ByVal Value As String)
                _Address2 = Value
            End Set
        End Property

        ''' <summary>
        ''' City Property (r/w)
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property City() As String
            Get
                Return _City
            End Get

            Set(ByVal Value As String)
                _City = Value
            End Set
        End Property

        ''' <summary>
        ''' State Property (r/w)
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property State() As String
            Get
                Return _State
            End Get

            Set(ByVal Value As String)
                _State = Value
            End Set
        End Property

        ''' <summary>
        ''' Postcode Property (r/w)
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Postcode() As String
            Get
                Return _Postcode
            End Get

            Set(ByVal Value As String)
                _Postcode = Value
            End Set
        End Property

        ''' <summary>
        ''' Country Property (r/w)
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Country() As String
            Get
                Return _Country
            End Get

            Set(ByVal Value As String)
                _Country = Value
            End Set
        End Property

        ''' <summary>
        ''' PhoneNumber Property (r/w)
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property PhoneNumber() As String
            Get
                Return _PhoneNumber
            End Get

            Set(ByVal Value As String)
                _PhoneNumber = Value
            End Set
        End Property

        ''' <summary>
        ''' Password2 Property (r/w)
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Password2() As String
            Get
                Return _Password2
            End Get

            Set(ByVal Value As String)
                _Password2 = Value
            End Set
        End Property

        ''' <summary>
        ''' Currency Property (r/w)
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Currency() As Integer
            Get
                Return _Currency
            End Get

            Set(ByVal Value As Integer)
                _Currency = Value
            End Set
        End Property

        ''' <summary>
        ''' GroupId Property (r/w)
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property GroupId() As Integer
            Get
                Return _GroupId
            End Get

            Set(ByVal Value As Integer)
                _GroupId = Value
            End Set
        End Property

        ''' <summary>
        ''' Notes Property (r/w)
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Notes() As String
            Get
                Return _Notes
            End Get

            Set(ByVal Value As String)
                _Notes = Value
            End Set
        End Property

        ''' <summary>
        ''' CCType Property (r/w)
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property CCType() As String
            Get
                Return _CCType
            End Get

            Set(ByVal Value As String)
                _CCType = Value
            End Set
        End Property

        ''' <summary>
        ''' CardNum Property (r/w)
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property CardNum() As String
            Get
                Return _CardNum
            End Get

            Set(ByVal Value As String)
                _CardNum = Value
            End Set
        End Property

        ''' <summary>
        ''' ExpDate Property (r/w)
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property ExpDate() As String
            Get
                Return _ExpDate
            End Get

            Set(ByVal Value As String)
                _ExpDate = Value
            End Set
        End Property

        ''' <summary>
        ''' StartDate Property (r/w)
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property StartDate() As String
            Get
                Return _StartDate
            End Get

            Set(ByVal Value As String)
                _StartDate = Value
            End Set
        End Property

        ''' <summary>
        ''' IssueNumber Property (r/w)
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property IssueNumber() As String
            Get
                Return _IssueNumber
            End Get

            Set(ByVal Value As String)
                _IssueNumber = Value
            End Set
        End Property

        ''' <summary>
        ''' CustomFields Property (r/w)
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property CustomFields() As String
            Get
                Return _CustomFields
            End Get

            Set(ByVal Value As String)
                _CustomFields = Value
            End Set
        End Property

        ''' <summary>
        ''' NoEmail Property (r/w)
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property NoEmail() As Boolean
            Get
                Return _NoEmail
            End Get

            Set(ByVal Value As Boolean)
                _NoEmail = Value
            End Set
        End Property

        ''' <summary>
        ''' SkipValidation Property (r/w)
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property SkipValidation() As Boolean
            Get
                Return _SkipValidation
            End Get

            Set(ByVal Value As Boolean)
                _SkipValidation = Value
            End Set
        End Property



#End Region

#Region "Public Methods"

        ' -----------------------------------------------
        ' -- Public Methods
        ' -----------------------------------------------



#End Region

#Region "Constructors"

        ' -----------------------------------------------
        ' -- Constructor
        ' -----------------------------------------------	

        ''' <summary>
        ''' New Constructor
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub New()
        End Sub

        Public Sub New(ByVal FirstName As String, ByVal LastName As String, ByVal CompanyName As String, ByVal Email As String, ByVal Address1 As String, ByVal Address2 As String, ByVal City As String, ByVal State As String, ByVal Postcode As String, ByVal Country As String, ByVal PhoneNumber As String, ByVal Password2 As String, ByVal Currency As Integer, ByVal GroupId As Integer, ByVal Notes As String, ByVal CCType As String, ByVal CardNum As String, ByVal ExpDate As String, ByVal StartDate As String, ByVal IssueNumber As String, ByVal CustomFields As String, ByVal NoEmail As Boolean, ByVal SkipValidation As Boolean)
            _FirstName = FirstName
            _LastName = LastName
            _CompanyName = CompanyName
            _Email = Email
            _Address1 = Address1
            _Address2 = Address2
            _City = City
            _State = State
            _Postcode = Postcode
            _Country = Country
            _PhoneNumber = PhoneNumber
            _Password2 = Password2
            _Currency = Currency
            _GroupId = GroupId
            _Notes = Notes
            _CCType = CCType
            _CardNum = CardNum
            _ExpDate = ExpDate
            _StartDate = StartDate
            _IssueNumber = IssueNumber
            _CustomFields = CustomFields
            _NoEmail = NoEmail
            _SkipValidation = SkipValidation
        End Sub


#End Region

#Region "Private Methods"

        ' -----------------------------------------------
        ' -- Private Methods
        ' -----------------------------------------------
        ' Your Private Methods Go Here.

#End Region

#Region "Supporting Objects"

        ''' <summary>
        ''' Some Utilities used by these classes
        ''' </summary>
        ''' <remarks></remarks>
        Public Class Utilities

            ''' <summary>
            ''' CheckNull Method
            ''' If Item is Nothing then Returns Nothing rather than DbNull
            ''' </summary>
            ''' <param name="Item"></param>
            ''' <returns></returns>
            ''' <remarks></remarks>
            Public Shared Function CheckNull(ByVal Item As Object) As Object
                If Item Is System.DBNull.Value Then
                    Return Nothing
                Else
                    Return Item
                End If
            End Function

            ''' <summary>
            ''' CStrEx Method
            ''' A CStr function that doesn't cause an exception when a DBNull is encountered
            ''' </summary>
            ''' <param name="test"></param>
            ''' <returns></returns>
            ''' <remarks></remarks>
            Public Shared Function CStrEx(ByVal test As Object) As String
                If IsDBNull(test) Then
                    Return ("")
                Else
                    Return CStr(test)
                End If
            End Function

            ''' <summary>
            ''' CBoolEx Method
            ''' A CBool function that doesn't cause an exception when a DBNull is encountered
            ''' </summary>
            ''' <param name="test"></param>
            ''' <returns></returns>
            ''' <remarks></remarks>
            Public Shared Function CBoolEx(ByVal test As Object) As Boolean
                If IsDBNull(test) Then
                    Return False
                Else
                    Return CBool(test)
                End If
            End Function

            ''' <summary>
            ''' CIntEx Method
            ''' A CInt function that doesn't cause an exception when a DBNull is encountered
            ''' </summary>
            ''' <param name="test"></param>
            ''' <returns></returns>
            ''' <remarks></remarks>
            Public Shared Function CIntEx(ByVal test As Object) As Integer
                If IsDBNull(test) Then
                    Return 0
                Else
                    Return CInt(test)
                End If
            End Function

        End Class


        ''' <summary>
        ''' A Local debugging object
        ''' </summary>
        ''' <remarks></remarks>
        Class Debug

            Public Enum LogLevel As Integer
                NoLogging = 0
                Normal = 1
                Verbose = 2
                Debug = 3
            End Enum

            ''' <summary>
            ''' A Simple Logging Method
            ''' </summary>
            ''' <param name="Text"></param>
            ''' <param name="Logtype"></param>
            ''' <param name="Level"></param>
            ''' <param name="Success"></param>
            ''' <param name="WriteToEventLog"></param>
            ''' <param name="Filename"></param>
            ''' <param name="WriteToConsole"></param>
            ''' <param name="IncludePrefix"></param>
            ''' <param name="IncludeTime"></param>
            ''' <remarks></remarks>
            Public Shared Sub Log(ByVal Text As String, _
                                      Optional ByVal Logtype As EventLogEntryType = EventLogEntryType.Information, _
                                      Optional ByVal Level As LogLevel = LogLevel.Normal, _
                                      Optional ByVal Success As Boolean = True, _
                                      Optional ByVal WriteToEventLog As Boolean = True, _
                                      Optional ByVal Filename As String = "", _
                                      Optional ByVal WriteToConsole As Boolean = False, _
                                      Optional ByVal IncludePrefix As Boolean = True, _
                                      Optional ByVal IncludeTime As Boolean = True)

                ' Secura.Debug.Log(Text, Logtype, CType(Level, Secura.AddClient.Debug.LogLevel), Success, WriteToEventLog, Filename, WriteToConsole, IncludePrefix, IncludeTime)
                Trace.Write(LogType.ToString() & ": " & Text, "Secura.WHMCS.AddClient")

            End Sub

        End Class
#End Region

    End Class

#Region "Collection"

    Public Class AddClientCollection
        Inherits Secura.WHMCS.CollectionHelpers.AddClientBase.SortableCollectionBase

        Public Sub New()
            MyBase.SortObjectType = GetType(AddClient)
        End Sub

        ' ------------------------------------------------------------------------
        ' -- Property: Count
        ' -- Gets the number of elements contained in the Collection instance.
        ' -- This property is inherited from CollectionBase and available by default.
        ' ------------------------------------------------------------------------	

        ' ------------------------------------------------------------------------
        ' -- Property: Item
        ' -- Gets or sets the element at the specified index.
        ' ------------------------------------------------------------------------
        Default Public Property Item(ByVal Index As Integer) As AddClient
            Get
                Return CType(MyBase.List.Item(Index), AddClient)
            End Get
            Set(ByVal Value As AddClient)
                MyBase.List.Item(Index) = Value
            End Set
        End Property

        ' ------------------------------------------------------------------------
        ' -- Method: Clear
        ' -- Removes all objects from the CollectionBase instance
        ' -- This Method is inherited from CollectionBase and is available by default.
        ' ------------------------------------------------------------------------	
        'Public Function Clear() As Integer
        '	MyBase.List.Clear
        'End Function


        ' ------------------------------------------------------------------------
        ' -- Method: Add
        ' -- Searches Adds an object to the end of the Collection. 
        ' ------------------------------------------------------------------------	
        Public Function Add(ByVal Item As AddClient) As Integer
            Return MyBase.List.Add(Item)
        End Function

        ' ------------------------------------------------------------------------
        ' -- Method: IndexOf
        ' -- Searches for the specified Object and returns the zero-based index of 
        ' -- the first occurrence within the entire Collection.
        ' ------------------------------------------------------------------------
        Public Function IndexOf(ByVal Item As AddClient) As Integer
            Return MyBase.List.IndexOf(Item)
        End Function 'IndexOf

        ' ------------------------------------------------------------------------
        ' -- Method: Insert
        ' -- Inserts an element into the CollectionBase at the specified index. 
        ' ------------------------------------------------------------------------	
        Public Sub Insert(ByVal Index As Integer, ByVal Item As AddClient)
            MyBase.List.Insert(Index, Item)
        End Sub 'Insert

        ' ------------------------------------------------------------------------
        ' -- Method: Remove
        ' -- Removes the first occurrence of a specific object from the Collection. 
        ' ------------------------------------------------------------------------	
        Public Sub Remove(ByVal Item As AddClient)
            MyBase.List.Remove(Item)
        End Sub 'Remove

        ' ------------------------------------------------------------------------
        ' -- Method: RemoveAt
        ' -- Removes the first occurrence of a specific object from the Collection. 
        ' ------------------------------------------------------------------------	
        'Public Sub Remove(ByVal Item As AddClient)
        '	MyBase.List.Remove(Item)
        'End Sub 'Remove

        ' ------------------------------------------------------------------------
        ' -- Method: Contains
        ' -- Determines whether the CollectionBase contains a specific element. 
        ' ------------------------------------------------------------------------
        Public Function Contains(ByVal Item As AddClient) As Boolean
            ' If value is not of type AddClient, this will return false.
            Return MyBase.List.Contains(Item)
        End Function 'Contains

    End Class

#End Region

End Namespace

Namespace Secura.WHMCS.CollectionHelpers.AddClientBase

#Region " ** Interface Definitions ** "
    Public Interface IGenericComparer
        Inherits IComparer

        'IGeneriComparer Extends IComparer to include ObjectType,
        'SortByName, And SortingOrder Properties

        Property SortObjectType() As System.Type
        Property SortByName() As String
        Property SortDirection() As Integer
    End Interface

    Public Interface ISortable
        'A new interface for the abstract implementation that
        'includes our Sort method

        Property SortObjectType() As System.Type
        Property SortByName() As String
        Property SortDirection() As GenericComparer.SorterDirection

        Sub Sort()
    End Interface
#End Region

    '-----------------------------------------
    '----- Generic Comparer Class
    '----- This Class Implements the IGenericComparer interface
    '-----------------------------------------
#Region " ** GenericComparer Class ** "
    Public NotInheritable Class GenericComparer 'Sealed class
        Implements IGenericComparer

        Public Enum SorterDirection
            Ascending = 0
            Descending = 1
        End Enum

        Private m_SortObjectType As System.Type
        Private m_SortByName As String = ""
        Private m_SortDirection As Integer = 0

        Property SortObjectType() As System.Type Implements IGenericComparer.SortObjectType
            Get
                Return m_SortObjectType
            End Get
            Set(ByVal value As System.Type)
                m_SortObjectType = value
            End Set
        End Property

        Property SortByName() As String Implements IGenericComparer.SortByName
            Get
                Return m_SortByName
            End Get
            Set(ByVal value As String)
                m_SortByName = value
            End Set
        End Property

        Property SortDirection() As Integer Implements IGenericComparer.SortDirection
            Get
                Return m_SortDirection
            End Get
            Set(ByVal value As Integer)
                m_SortDirection = value
            End Set
        End Property

        Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements IComparer.Compare
            'Basedon the property name we have to get the property info
            Dim oPropertyInfo As PropertyInfo = SortObjectType.GetProperty(m_SortByName)

            'Nowthat we have the property Info we can get the value of each of theproperties
            'castas IComparable objects
            Dim object1 As IComparable = DirectCast(oPropertyInfo.GetValue(x, Nothing), IComparable)
            Dim object2 As IComparable = DirectCast(oPropertyInfo.GetValue(y, Nothing), IComparable)

            'Nowall we have to do is compare the properties with the CompareTo method
            'Inheritedfrom IComparable
            If SortDirection = 0 Then
                Return (object1.CompareTo(object2))
            Else
                Return (object2.CompareTo(object1))
            End If
        End Function

    End Class
#End Region

    '-----------------------------------------
    '----- Abstract Implementation Class -----
    '-----------------------------------------
#Region " ** SortableCollectionBase Class** "
    Public MustInherit Class SortableCollectionBase
        Inherits Collections.CollectionBase
        Implements ISortable

        'Thisclass must be inherited and is our new Collection Class inheritedfrom
        'CollectionBaseand implementing our ISortable interface

        Private m_SortByName As String = ""
        Private m_SortDirection As GenericComparer.SorterDirection
        Private m_SortObjectType As System.Type

        Public Property SortByName() As String Implements ISortable.SortByName
            Get
                Return m_SortByName
            End Get
            Set(ByVal value As String)
                m_SortByName = value
            End Set
        End Property

        Public Property SortDirection() As GenericComparer.SorterDirection Implements ISortable.SortDirection
            Get
                Return m_SortDirection
            End Get
            Set(ByVal value As GenericComparer.SorterDirection)
                m_SortDirection = value
            End Set
        End Property

        Public Property SortObjectType() As System.Type Implements ISortable.SortObjectType
            Get
                Return m_SortObjectType
            End Get
            Set(ByVal value As System.Type)
                m_SortObjectType = value
            End Set
        End Property

        Overridable Sub Sort() Implements ISortable.Sort
            If m_SortByName = "" Then Throw New Exception("First Set SortByName")
            If m_SortObjectType Is Nothing Then Throw New Exception("First Set theSortObjectType")

            Dim oSorter As IGenericComparer = New GenericComparer()
            oSorter.SortObjectType = m_SortObjectType
            oSorter.SortByName = m_SortByName
            oSorter.SortDirection = CInt(m_SortDirection)

            InnerList.Sort(oSorter)
        End Sub

    End Class
#End Region

End Namespace